//
//  HMMainViewController.swift
//  Weibo-walker
//
//  Created by 郭彬 on 16/3/2.
//  Copyright © 2016年 guobin. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = HMTabBar()
        tabBar.composeButtonClosure = {
            print("撰写按钮点击")
        }
        setValue(tabBar, forKey: "tabBar")
        
        addChildVc()

    }


    func addChildVc(){
        
        addChildViewController(HMHomeTableViewController(), title: "首页", imgNamed: "tabbar_home")
        
        addChildViewController(HMMessageTableViewController(), title: "消息", imgNamed: "tabbar_message_center")
        
        addChildViewController(HMDiscoverTableViewController(), title: "发现", imgNamed: "tabbar_discover")
        
        addChildViewController(HMProfileTableViewController(), title: "我的", imgNamed: "tabbar_profile")

    }
    
    
    func addChildViewController(childController: UIViewController,title:String,imgNamed:String) {
        
        //设置名字
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: imgNamed)
        
        //选中状态的图片
        childController.tabBarItem.selectedImage = UIImage(named:"\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
       
        //设置文字的颜色
        //先定义前景色的属性
        let attributed = [
        
            NSForegroundColorAttributeName :UIColor.orangeColor()
        ]
        childController.tabBarItem.setTitleTextAttributes(attributed, forState: .Selected)
        
        //设置文字大小
        //先定义字体的属性
        let fontAttr = [
        
            NSFontAttributeName: UIFont.systemFontOfSize(15)
        ]
        
        childController.tabBarItem.setTitleTextAttributes(fontAttr, forState: UIControlState.Normal)
        
        //设置控制器
        addChildViewController(UINavigationController(rootViewController: childController))
        
        
        
    }
    
//    func addChildViewController(childController: UIViewController, title: String, imgNamed: String) {
//        
//        // 设置 title
//        childController.title = title
//        //        childController.navigationItem.title = title
//        //        childController.tabBarItem.title = title
//        
//        // 设置显示的图标
//        childController.tabBarItem.image = UIImage(named: imgNamed)
//        // 让图标原样显示
//        childController.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
//        
//        // 设置文字颜色
//        let attributed = [
//            NSForegroundColorAttributeName: UIColor.orangeColor()
//        ]
//        childController.tabBarItem.setTitleTextAttributes(attributed, forState: UIControlState.Selected)
//        
//        // 设置文字大小
//        //        let fontAttr = [
//        //            NSFontAttributeName: UIFont.systemFontOfSize(30)
//        //        ]
//        //        childController.tabBarItem.setTitleTextAttributes(fontAttr, forState: UIControlState.Normal)
//        
//        // 可以通过这种方式去调整图片位置
//        // childController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
//        
//        // 添加子控制器
//        addChildViewController(UINavigationController(rootViewController: childController))
//    }


}
